﻿@model PagedList<LogInLog>

@{
    ViewBag.Title = "系统日志";
}

<section class="content-header">
    <h1>
        系统日志
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home", new { area = "" })">首页</a></li>
        <li class="active"><a href="@Url.Action("Index", "LogInlog")">系统日志</a></li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="box box-solid">
                <div class="box-nav clearfix">
                    @using (Ajax.BeginForm("Index", new RouteValueDictionary { { "id", "" } },
                        new AjaxOptions { UpdateTargetId = "datatable", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, LoadingElementId = "loadingPage", OnBegin = "$('#datatable').fadeOut('slow')", OnComplete = "$('#datatable').fadeIn('slow')" }, 
                        new RouteValueDictionary { { "id", "searchForm" }, { "class", "form-inline" } }))
                    {
                        <fieldset>
                            <div class="btn-group" id="time_horizon">
                                <input type="hidden" id="dateType" name="dateType" />
                                <button type="button" class="btn btn-default" data-value="today">今天</button>
                                <button type="button" class="btn btn-default active" data-value="week">近7天</button>
                                <button type="button" class="btn btn-default" data-value="month">近1个月</button>
                                <button type="button" class="btn btn-default" data-value="3month">近3个月</button>
                            </div>
                            <input id="keyWord" name="keyWord" type="text" class="form-control form-control-static" placeholder="姓名" maxlength="50">
                            <button id="btn_search" type="submit" class="btn btn-primary"><i class="fa fa-search">查询</i></button>
                            <button id="removelog" class="btn btn-primary" onclick="btn_removelog()"><i class="fa fa-eraser"></i>清空日志</button>
                        </fieldset>
                    }
                </div>
                <div class="box-body" id="datatable">
                    @Html.Partial("_AjaxLogInLogTable", Model)
                </div>
            </div>
        </div>
    </div>
</section>
<div class="modal" id="removeDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">清空日志</h4>
            </div>
            <div class="modal-body">
                <form id="form1">
                    <div class="form-group">
                        <select class="form-control required" id="keepTime" name="keepTime" required>
                            <option value="">==请选择保留时间==</option>
                            <option value="7">保留近一周</option>
                            <option value="1">保留近一个月</option>
                            <option value="3">保留近三个月</option>
                            <option value="0">不保留，全部删除</option>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                <button type="button" onclick="removelog()" class="btn btn-primary">确认</button>
            </div>
        </div>
    </div>
</div>
<div id="loadingPage1" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">@Resources.Global.LoadingMsg</div>
</div>

@section Scripts {
    @{Html.RegisterMvcPagerScriptResource();}
    <script type="text/javascript">
        $(document).ready(function () {
            //使用bootstrap样式的分页时，手机自适应收到影响，待玉杰解决
            $('#footable').footable({ "sort": false });
        });

        var dateType = $("#dateType").attr("value");

        $("#time_horizon button.btn-default").each(function () {
            if (!dateType) {
                dateType = "week";
            }
            if (dateType == $(this).attr('data-value')) {
                $("#time_horizon button.btn-default").removeClass("active");
                $(this).addClass("active");
            }
        });

        $("#time_horizon button.btn-default").click(function () {
            $("#time_horizon button.btn-default").removeClass("active");
            $(this).addClass("active");            
            $("#dateType").attr("value", $(this).attr('data-value'));
            //alert($("#dateType").attr("value"));
        });

        function btn_removelog() {
            $('#removeDlg').modal();
        }

        function removelog() {
            if (!$('#form1').formValid()) {
                return false;
            }
            $.submitForm({
                loading: "正在备份数据...",
                url: "/LogInLog/SubmitRemoveLog",
                param: $("#form1").formSerialize(),
                success: function () {
                    $('#removeDlg').modal("hide");
                }
            })
        }
    </script>
}